from threading import Thread
import time


class MyThread(Thread):
    def __init__(self, name):
        Thread.__init__(self)
        self.name = name

    def run(self):
        print(f"线程{self.name}启动")
        for i in range(3):
            print(f"线程{self.name} {i}")
            time.sleep(1)
        print(f"线程{self.name}结束")


if __name__ == "__main__":
    print("主线程启动")

    t1 = MyThread("foo")
    t2 = MyThread("bar")

    t1.start()
    t2.start()

    print("主线程结束")
